﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Fotobanka
{
    public partial class ListSkupin : System.Web.UI.Page
    {
        LoginInfo li;
        protected void Page_Load(object sender, EventArgs e)
        {
            li = (LoginInfo)Session["logged_user_id"];

            switch ((int)li.Role)
            {
                case (int)Utils.SystemRoles.Admin:
                    ObjectDataSource1.SelectMethod = "SelectAllGroups";
                    ObjectDataSource1.SelectParameters.Clear();
                    break;
                case (int)Utils.SystemRoles.Spravce:
                    ObjectDataSource1.SelectMethod = "SelectUserGroups";
                    if (ObjectDataSource1.SelectParameters["user_id"] == null)
                    {
                        ObjectDataSource1.SelectParameters.Add(new Parameter("user_id", TypeCode.Int32, li.Id.ToString()));
                    } 
                    break;
                case (int)Utils.SystemRoles.Uzivatel:
                    ObjectDataSource1.SelectMethod = "SelectUserGalleries";
                    //ObjectDataSource1.SelectParameters.Add(new Parameter("user_id", TypeCode.Int32, li.Id.ToString()));
                    GridView1.DataSource = null;
                    AddLink.Visible = false;
                    break;
                default:

                    break;
            }
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                foreach (DataControlField dcf in ((GridView)sender).Columns)
                {
                    if (dcf.ToString() == "CommandField")
                    {
                        if (((CommandField)dcf).ShowDeleteButton == true)
                        {
                            e.Row.Cells[((GridView)sender).Columns.IndexOf(dcf)].Attributes
                            .Add("onclick", "return confirm(\"Opravdu chcete smazat?\")");
                        }
                    }
                }
            }
        }
    }
}
